home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / tc2cs.arc / TC2CS.C < prev    next >
Text File  |  1987-06-11  |  4KB  |  177 lines

  1. /* TC2CS - Converts TurboC map file to one readable by Lattice C-Sprite debugger
  2.  *  Jim Deming  6-10-87   Terripin Station
  3.  *     The map file that is build by Turbo C is not acceptable by C-Sprite. This
  4.  *  program takes the Turbo map file and builds one that is acceptable by 
  5.  *  C-Sprite.  If you have a newer C-Sprite that doesn't like what I have done,
  6.  *  then you have the opportunity to improve on the following.
  7.  *  Assumptions:
  8.  *      - version 2.01 of C-Sprite, yes I know it is an old one. 
  9.  *      - version 1.0  of Turbo C
  10.  *      - PC DOS 3.2
  11.  *      - you do not need DGROUP & PGROUP that C-Sprite picks up from Lattice C
  12.  *      - I used the small memory model to build the .exe
  13.  *      - extension .TCM will not conflict with other files
  14.  */
  15. #include <dir.h>
  16. #include <fcntl.h>
  17. #include <stdio.h>
  18.  
  19. extern int errno;
  20.  
  21. char drive[MAXDRIVE];
  22. char dir[MAXDIR];
  23. char file[MAXFILE];
  24. char ext[MAXEXT];
  25.  
  26. /* full path names built in next two fields to test for double identity */
  27. char file1[MAXPATH];
  28. char file2[MAXPATH];
  29.  
  30. const char map_cnst[] = ".MAP";
  31. const char tcm_cnst[] = ".TCM"; 
  32. void usage();
  33.  
  34. void main(argc, argv)
  35. int argc;
  36. char *argv[];
  37. {
  38.     char *fone=NULL, *ftwo=NULL;
  39.     char name[MAXFILE];
  40.     FILE *fp1, *fp2, *fopen();
  41.     int i;
  42.      int first_time=1;
  43.      char string[128];
  44.                                 
  45. /* no command line arguments */
  46.     if (argc < 2) usage();
  47.  
  48. /* determine what files will be used */    
  49.     while ( *++argv )
  50.     {
  51.         if( fone )
  52.         {
  53.             if( ftwo )
  54.             {
  55.                 printf("tc2cs: too many parameters on command line\n\n");
  56.                 usage();
  57.             }
  58.             ftwo = *argv;
  59.         } else {
  60.             fone = *argv;
  61.             build_path( file1, fone );
  62.         }
  63.     }
  64.     strcpy( name, file );    /* file will be changed in build_path() */
  65.     if( ftwo )
  66.     {
  67.         if( !( build_path( file2, ftwo ) & FILENAME ) )
  68.         {
  69.             strcat( file2, name );
  70.             strcat( file2, map_cnst );
  71.         }
  72.     } else {
  73.         strcat( file2, file );
  74.         strcat( file2, map_cnst );
  75.         build_path( file2, file2 );
  76.     }
  77.  
  78. /* if source and target are the same, rename extension from MAP to TCM */
  79.     if( ! stricmp( file1, file2 ) )
  80.     {
  81.         printf("Changing the extension of %s to %s\n", file1, tcm_cnst );
  82.         strncpy( &file1[ strlen( file1 )-4 ], tcm_cnst, 4 );
  83.         unlink( file1 );
  84.         if( rename( file2, file1 ) )
  85.         {
  86.             printf("tc2cs: Rename failed with DOS error %x\n", errno );
  87.             exit(1);
  88.         }
  89.     }
  90. /*    
  91.     printf("%s\n", file1 );
  92.     printf("%s\n", file2 );
  93.   */
  94.   
  95. /* open files */
  96.     if ((fp1 = fopen( file1, "rt")) == NULL) 
  97.     {
  98.         printf("tc2cs: cannot open %s\n", file1);
  99.         exit(1);
  100.     }
  101.     if ((fp2 = fopen( file2, "wt")) == NULL) 
  102.     {
  103.         printf("tc2cs: cannot open target file %s\n", file2);
  104.         exit(1);
  105.     }
  106.  
  107. /* essense this program */
  108.     while( fgets(string, 128, fp1) )
  109.     {
  110.         if( first_time )
  111.         {
  112.             if( string[5] == ':' )
  113.             {
  114.                 first_time=0;
  115.                 fputs("  Address         Publics by Name\n\n", fp2);
  116.                 fputs("  Address         Publics by Value\n\n", fp2);
  117.             } else continue;
  118.         }
  119.         if( string[0] == ' ' )     /* C-Sprite likes upper case & no '@'s */
  120.         {
  121.             i = 17;
  122.             while( string[i] )
  123.             {
  124.                 if( string[i] == '@' )
  125.                     string[i] = 'A';
  126.                 else
  127.                     string[i] = toupper( string[i] );
  128.                 i++;
  129.             }
  130.         }
  131.         if( fputs( string, fp2 ) )
  132.         {
  133.             printf("tc2cs: Failed writing to target file.\n");
  134.             exit(1);
  135.         }
  136.     } /* endwhile */
  137.  
  138. /* close of program */
  139.     printf("Successful\n");
  140.     fclose(fp1);
  141.     fclose(fp2);
  142. }        
  143.     
  144. build_path( p, q )
  145. char *p, *q;
  146. {
  147.     int flag;
  148.     
  149.     flag = fnsplit( q, drive, dir, file, ext );        
  150.     if( !(flag & DRIVE) )
  151.     {
  152.         drive[0] = getdisk() + 'A';
  153.         drive[1] = ':';
  154.     }
  155.     *drive = toupper( *drive );
  156.     strcpy( p, drive );
  157.     if( !(flag & DIRECTORY) )
  158.     {
  159.         dir[0] = '\\';
  160.         getcurdir( drive[0]-'A'+1, &dir[1] );
  161.         strcat( dir, "\\" );
  162.     }
  163.     strcat( p, dir );
  164.     strcat( p, file );
  165.     strcat( p, ext );
  166.     return( flag );
  167. }
  168.  
  169. void usage()
  170. {
  171.  printf("Usage: tc2cs [a:][\path\]infile [b:][\path\][outfile]\n\n");
  172.  printf(" Takes a map file created by Turbo C and creates a map file to be\n");
  173.  printf("used by C-Sprite.  If the source file will have the same name as the\n");
  174.  printf("destination file, the source will be renamed with TCM extension.\n");
  175.  exit(0);
  176. }
  177.